package business.response;

import static common.Constant.CONTNO;
import static common.Constant.RATE;
import static common.Constant.TASK;
import static common.Constant.DONE;
import static common.Constant.COUNT;

import java.util.Map;

import redis.clients.jedis.JedisPubSub;

import common.util.RedisUtil;
import common.util.JsonUtil;

public class MonitorPubSub extends JedisPubSub {
    @Override
    public void onMessage(String tChannel, String tMessage) {
        String tJson = RedisUtil.rpop(TASK);
        if (tJson == null) {
            return;
        }
        Map<String, Object> tMap = JsonUtil.getMapObject(tJson);
        System.out.println(tMap.get(CONTNO) + " " + tMap.get(RATE));
        try {
            Thread.sleep((long) (Math.random() * 100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        RedisUtil.lpush(DONE, tMap.get(CONTNO).toString());
        RedisUtil.incr(COUNT);
    }
}
